<?php
require_once 'IEngine.php';
require_once 'simple_html_dom.php';

class ImdbEngine implements IEngine{
	private $tags = array("Movies");
	private $name = "IMDB";

	function search($term) {
		$results = array();
		$url = "http://www.imdb.com/find?s=tt&q=" . urlencode($term);
		$str = file_get_contents($url);
		$page = str_get_html($str);
		$res = $page->find("div#main > table > tr");
		foreach ($res as $child) {
			$result = array();
			$elem = $child->find("td");
			if (count($elem) != 3) continue;
			$title = $elem[2]->find("a");
			$result['title'] = $title[0]->innertext();
			$result['href'] = "http://www.imdb.com".$title[0]->attr['href'];
			$image = $elem[0]->innertext();
			$result['description'] = $image . str_replace($title[0]->outertext(),"",$elem[2]->innertext());
			$results[] = $result;
		}
		return $results;
	}

	public function getTags() {
		return $this->tags;
	}

	public function getName() {
		return $this->name;
	}

	public function engineLogo() {
		return '<img class="enginelogo" src="http://i.imdb.com/favicon.ico" />';
	}
}
?>